﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DuLieu;

namespace SearchEngineer
{
    public class Search
    {
        public static List<string> GoiYTenDiaDiem(string searchKey)
        {
            List<string> result = new List<string>();
            DataSet1TableAdapters.TENDIADIEMTableAdapter db = new DataSet1TableAdapters.TENDIADIEMTableAdapter();
            DataSet1.TENDIADIEMDataTable tb1 = new DataSet1.TENDIADIEMDataTable();
            db.FillTenDiaDiemBy(tb1, searchKey, searchKey);
            int addCount = 5 - tb1.Count;
            if (addCount > 0)
            {
                string searchKey2 = Common.RejectMarks(searchKey);
                if (!searchKey.Equals(searchKey2))
                {
                    DataSet1.TENDIADIEMDataTable tb2 = new DataSet1.TENDIADIEMDataTable();
                    db.FillTenDiaDiemBy(tb2, searchKey2, searchKey2);
                    for (int i = 0; i < addCount && i < tb2.Count; i++)
                    {
                        DataSet1.TENDIADIEMRow row =
                        tb1.NewTENDIADIEMRow();

                        row.TenDiaDiem = tb2[i].TenDiaDiem;
                        tb1.AddTENDIADIEMRow(row);
                    }
                }
            }

            for (int i = 0; i < tb1.Count; i++)
            {
                result.Add(tb1[i].TenDiaDiem);
            }
            return result;
        }
    }
}
